package linkedtable;

/**
 * @Description 328. 奇偶链表 https://leetcode.cn/problems/odd-even-linked-list/
 * @Author Firenut
 * @Date 2023-02-02 10:45
 */
public class T328_oddEvenList {
    public ListNode oddEvenList(ListNode head) {
        if(head==null){
            return null;
        }
        ListNode p,q,qhead;
        p=head;
        q=head.next;
        qhead=q;
        while (q != null && q.next != null) {
            p.next = q.next;
            p = q.next;
            q.next = p.next;
            q = p.next;
        }
        p.next=qhead;
        return head;
    }
}